import json
import requests
import re
import os
from core.util import dir_create
import setting as c
from core.log import logger

dt_nav = [
        ('答题签到', [('答题签到', 53, 5)]),
        ('节日活动', [('元宵灯谜', 17 ,4), ('看图说话', 31 ,0), ('课堂修行', 32 ,0), ('谁是学霸', 33 ,0), ('文星赛诗会', 34 ,0)]),
        ('副本', [('车迟斗法', 9, 3), ('四季', 14, 0), ('通天河', 10, 0), ('黑风山', 12, 0), ('四门绝阵', 30, 0), ('剑灵魔影', 45 ,0), ('大闹天宫', 46 ,0), ('衣冠古丘', 54 ,0), ('胡姬琵琶行', 13 ,0)] ),
        ('科举', [('乡试', 15 ,1), ('会试', 16 ,1), ('附加题', 35 ,0), ('汉语知识附加题', 36 ,0), ('常用英语附加题', 37 ,0), ('生活常识附加题', 38 ,0), ('网易邮箱附加题', 39 ,0), ('敦煌风情附加题', 40 ,0), ('文韵墨香', 41 ,0), ('全民知识赛', 42 ,0)]),
        ('本事和尚', [('本事和尚', 18 ,0)]),
        ('房都尉', [('房都尉', 25 ,2)]),
        ('诗中仙', [('诗中仙', 23 ,0)]),
        ('术中仙', [('术中仙', 24 ,0)]),
        ('师徒任务', [('师徒任务', 52 ,0)]),
        ('日常活动', [('寻梦追忆', 50 ,0), ('降妖伏魔', 57 ,0), ('卡牌风云赛', 48 ,0)]),
        ('三界书院', [('三界书院', 3 ,0)]),
        ('翰墨抄写', [('翰墨抄写', 11 ,0)]),
        ('赛诗大会', [('赛诗大会', 1 ,0)]),
        ('梦幻课堂', [('梦幻课堂', 7 ,0)]),
        ('异域欢歌', [('异域欢歌', 47 ,0)]),
        ('六艺修行', [('六艺修行', 29 ,0)]),
        ('幻境节日', [('幻境节日', 43 ,0)]),
        ('密保节', [('密保节', 2 ,0)]),
        ('战神山', [('战神山', 26 ,0)]),
        ('梦游志', [('梦游志', 22 ,0)]),
        ('答题卡', [('答题卡', 49 ,0)]),
        ('知识教导', [('知识教导', 27 ,0)]),
        ('帮派密道', [('帮派密道', 28 ,0)]),
        ('百万梦幻', [('百万梦幻', 55 ,0)]),
    ]


def download_image(url, path):
    # 发送HTTP GET请求下载图片
    url = f"{c.URL_IMAGE}/{url}"
    logger.info(f"{url} {path}")
    response = requests.get(url)

    # 检查请求是否成功
    if response.status_code == 200:
        # 将图片内容写入文件
        parent_directory = os.path.dirname(path)
        dir_create(parent_directory)
        with open(path, 'wb') as file:
            file.write(response.content)
        logger.info(f"图片已下载并保存到 {path}")
    else:
        logger.info(f"下载失败, HTTP 状态码：{response.status_code}")
